package com.masterclient.app.modules.income.adapter;

import android.view.ViewGroup;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.eoner.baselibrary.bean.aftersale.IncomeCommisssionFilterBean;
import com.masterclient.app.R;

import java.util.ArrayList;
import java.util.List;


/**
 * @auther hjian
 * @date 2020/6/15
 */

public class IncomeFilterAdapter extends BaseQuickAdapter<IncomeCommisssionFilterBean, BaseViewHolder> {

    private int type;
    private boolean isMultiple;
    private List<String> selectPositions;

    public IncomeFilterAdapter(int type, boolean isMultiple) {
        super(R.layout.item_filter);
        this.type = type ;
        this.isMultiple = isMultiple;
        selectPositions = new ArrayList<>();
    }


    @Override
    protected void convert(BaseViewHolder helper, IncomeCommisssionFilterBean item) {
        TextView tv = helper.getView(R.id.item_text_root);
        tv.setText(item.getName());
        if (type == 1)tv.getLayoutParams().width = ViewGroup.LayoutParams.WRAP_CONTENT;
        if(selectPositions.contains(item.getVal())){
            tv.setBackgroundResource(R.drawable.shape_team_select);
            tv.setTextColor(0xFFF23051);
        }else {
            tv.setBackgroundResource(type == 0?R.drawable.shape_team_default:R.drawable.shape_round_f0f2f5);
            tv.setTextColor(0xFF141922);
        }
    }

    public List<String> getSelectPositions() {
        return selectPositions;
    }

    public void setPosition(String valSelect) {
        if (selectPositions.contains(valSelect)){
            selectPositions.remove(valSelect);
        }else {
            if (isMultiple){
                selectPositions.add(valSelect);
            }else {
                selectPositions.clear();
                selectPositions.add(valSelect);
            }
        }
        notifyDataSetChanged();
    }

    public void clearSelection(){
        selectPositions.clear();
        notifyDataSetChanged();
    }

}
